<template>
  <div id="app">
    <nav class="bg-gray-800 p-4">
      <div class="container mx-auto">
        <a href="https://gitee.com/liu-meixi_0/to-do-list.git" class="text-white text-xl" target="_blank">查看 Gitee 源码</a>
      </div>
    </nav>
    <div class="container mx-auto p-4">
      <h1 class="text-3xl font-bold mb-4">ToDo List</h1>
      <ToDoInput @add-todo="addTodo" />
      <ToDoList :todos="todos" @delete-todo="deleteTodo" />
      <div class="mt-4">
        <p>剩余待办事项: {{ remainingTodos }}</p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import ToDoInput from './components/ToDoInput.vue';
import ToDoList from './components/ToDoList.vue';

interface Todo {
  id: number;
  text: string;
  completed: boolean;
}

const todos = ref<Todo[]>([]);

const addTodo = (newTodo: string) => {
  todos.value.push({ id: Date.now(), text: newTodo, completed: false });
};

const deleteTodo = (id: number) => {
  todos.value = todos.value.filter((todo) => todo.id !== id);
};

const remainingTodos = computed(() => {
  return todos.value.filter((todo) => !todo.completed).length;
});

onMounted(() => {
  console.log('ToDoList 应用已挂载');
});
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>    